package cn.yuanqiao.web.controller.archive.storeRoom;

import cn.yuanqiao.archive.storeRoom.service.InitializationService;
import cn.yuanqiao.common.core.domain.R;
import cn.yuanqiao.common.domain.YqField;
import cn.yuanqiao.common.domain.YqTable;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RequestMapping("/archive/initialization")
@RestController
public class InitializationController extends BaseController {

    @Autowired
    private InitializationService initializationService;


    @RequestMapping("/archive/table")
    public AjaxResult initializationTable() {

        initializationService.initializationTable();
        return AjaxResult.success();
    }

    @RequestMapping("/archive/getTableList")
    public R<List<YqTable>> getTableList() {

        List<YqTable> tableList = initializationService.getTableList();
        return R.ok(tableList);
    }

    @RequestMapping("/archive/getFieldList/{tableId}")
    public R<TableDataInfo> getFieldList(@PathVariable("tableId") String tableId, String pageNum, String pageSize) {
        startPage();
        List<YqField> fieldList = initializationService.getFieldList(tableId);
        return R.ok(getDataTable(fieldList));
    }


    @RequestMapping("/archive/getFieldListNoPage/{tableId}")
    public R<List<YqField>> getFieldListNoPage(@PathVariable("tableId") String tableId, String pageNum, String pageSize) {
        List<YqField> fieldList = initializationService.getFieldList(tableId);
        return R.ok(fieldList);
    }




}
